package com.yjhb.android.sbz.adapter.reward;

import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.reward.Reward;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;
import com.jojo.android.zxlib.tool.ZxSpanTool;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2021/1/15 14:14
 */
public class PromotionRewardAdapter extends BaseRecyclerAdapter<PromotionRewardAdapter.Holder, Reward> {
    private final String TAG = "PromotionRewardAdapter";


    public PromotionRewardAdapter(Context context) {
        super(context);
    }

    @Override
    protected Holder getHolder(View v) {
        return new Holder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_reward;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        if (position < 9) {
            holder.numTv.setText("0" + (position + 1));
        } else {
            holder.numTv.setText("" + (position + 1));
        }
        holder.targetTv.setText(getTarget("" + entity.getMin(), "" + entity.getMax()));
        holder.rewardTv.setText(getMoney(entity.getMoney()));
        holder.progressbar.setMax(entity.getMin());
        if (entity.getCurr()>=entity.getMin()){
            holder.progressbar.setProgress(entity.getMin());
        }else {
            holder.progressbar.setProgress(entity.getCurr());
        }
    }

    private CharSequence getMoney(String money) {
        if (TextUtils.isEmpty(money)) return "";
        CharSequence m = ZxSpanTool.ZoomSpan("奖励:￥" + money, 4,
                4 + money.length(), 1.5f);
        m = ZxSpanTool.StyleSpan(m, 3, 4 + money.length(), Typeface.BOLD);
        return m;
    }

    private CharSequence getTarget(String minMoney, String maxMoney) {
        String targetMoney = null;
        if (!maxMoney.equals("-1")) {
            targetMoney = "￥" + minMoney + "-" + maxMoney;
        } else {
            targetMoney = "￥" + minMoney + "以上";
        }
        CharSequence money = ZxSpanTool.ColorSpan("一二级好友完成总金额:" + targetMoney, 11,
                11 + targetMoney.length(),
                context.getResources().getColor(R.color.red_2c));
        money = ZxSpanTool.ZoomSpan(money, 11, 11 + targetMoney.length(), 1.2f);
        return money;
    }


    class Holder extends RecyclerView.ViewHolder {
        @BindView(R.id.num_tv)
        TextView numTv;
        @BindView(R.id.target_tv)
        TextView targetTv;
        @BindView(R.id.progressbar)
        ProgressBar progressbar;
        @BindView(R.id.reward_tv)
        TextView rewardTv;

        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
